<template>
	<view class="content">
		<u-form :model="data.formData" :error-type="['toast']" ref="form1">
			<u-form-item required label="面试人" prop="fullname" label-position="top">
				<u-input v-model="data.formData.fullname" placeholder="请输入面试人" disabled />
			</u-form-item>
			<u-form-item required label="面试职位" prop="interview_date" label-position="top">
				<view class="u-flex u-flex-1 u-row-between" @click="data.isInterviewJob=true">
					<u-input v-model="data.formData.jobname" placeholder="请选择面试职位" disabled
						@click="data.isInterviewJob=true" />
					<u-icon name="arrow-right" color="#bbbbbb" size="40"></u-icon>
				</view>
			</u-form-item>
			<u-form-item required label="面试日期" prop="interview_date" label-position="top">
				<view class="u-flex u-flex-1 u-row-between" @click="data.isInterviewDate=true">
					<u-input v-model="data.formData.interview_date" placeholder="请选择面试日期" disabled
						@click="data.isInterviewDate=true" />
					<u-icon name="arrow-right" color="#bbbbbb" size="40"></u-icon>
				</view>
			</u-form-item>
			<u-form-item required label="面试时间" prop="interview_time" label-position="top">
				<view class="u-flex u-flex-1 u-row-between" @click="data.isInterviewTime=true">
					<u-input v-model="data.formData.interview_time" placeholder="请选择面试时间" disabled
						@click="data.isInterviewTime=true" />
					<u-icon name="arrow-right" color="#bbbbbb" size="40"></u-icon>
				</view>
			</u-form-item>
			<u-form-item required label="面试地点" prop="address" label-position="top">
				<u-input v-model="data.formData.address" placeholder="请输入面试地点" />
			</u-form-item>
			<u-form-item required label="联系人" prop="contact" label-position="top">
				<u-input v-model="data.formData.contact" placeholder="请输入联系人" />
			</u-form-item>
			<u-form-item required label="联系电话" prop="tel" label-position="top">
				<u-input type="number" v-model="data.formData.tel" maxlength="11" placeholder="请输入联系电话" />
			</u-form-item>
			<u-form-item label="备注" prop="note" label-position="top">
				<u-input type="textarea" maxlength="100" v-model="data.formData.note" placeholder="请输入备注" />
			</u-form-item>
		</u-form>

		<!-- 职位选择 -->
		<u-select v-model="data.isInterviewJob" :list="data.jobList" value-name="id" label-name="jobname"
			@confirm="jobConfirm"></u-select>
		<u-picker mode="time" v-model="data.isInterviewDate" @confirm="interviewDate"></u-picker>
		<u-picker mode="time" v-model="data.isInterviewTime" :params="data.params" @confirm="interviewTime"></u-picker>

		<u-bottom-button confirmText="发送面试邀请" @confirm="submit"></u-bottom-button>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from "vue";
	import {
		onReady,
		onLoad
	} from '@dcloudio/uni-app'
	const form1 = ref();
	const data = reactive({
		formData: {
			type: '1',
			fullname: "",
			jobid: "",
			jobname: "",
			interview_date: "",
			interview_time: "",
			address: "",
			contact: "",
			tel: "",
			note: ""
		},
		rules: {
			jobid: [{
				required: true,
				message: '请选择面试职位',
				trigger: 'change'
			}],
			interview_date: [{
				required: true,
				message: '请选择面试日期',
				trigger: 'change',
			}],
			interview_time: [{
				required: true,
				message: '请选择面试时间',
				trigger: 'change',
			}],
			address: [{
				required: true,
				message: '请输入面试地点',
				trigger: 'change',
			}],
			contact: [{
				required: true,
				message: '请输入联系人',
				trigger: 'change',
			}, {
				validator: (rule, value, callback) => {
					return uni.$u.test.name(value);
				},
				message: '请输入正确的联系人'
			}],
			tel: [{
				required: true,
				message: '请输入联系电话',
				trigger: 'change',
			}, {
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value);
				},
				message: '请输入正确的联系电话'
			}]
		},
		// 职位
		jobList: [],
		isInterviewJob: false,
		// 日期
		isInterviewDate: false,
		// 时间
		isInterviewTime: false,
		params: {
			year: false,
			month: false,
			day: false,
			hour: true,
			minute: true,
			second: false
		}

	});
	onReady(() => {
		form1.value.setRules(data.rules)
	})
	onLoad(({
		fullname,
		resumeid
	}) => {
		getJobList()
		data.formData.fullname = fullname
		data.formData.resume_id = resumeid
	})
	const jobConfirm = (e) => {
		data.formData.jobid = e[0].value
		data.formData.jobname = e[0].label
	}
	const interviewTime = (e) => {
		data.formData.interview_time = e.hour + ':' + e.minute
	}
	const interviewDate = (e) => {
		data.formData.interview_date = e.year + '-' + e.month + '-' + e.day
	}
	// 获取职位列表
	const getJobList = async () => {
		let res = await uni.$u.api.getRecommendJobList()
		data.jobList = res.items
	}
	// 发送面试邀请
	const submit = () => {
		form1.value.validate(async valid => {
			if (valid) {
				let res = await uni.$u.api.getInterviewSave(data.formData)
				if (res) {
					uni.$u.toast('邀请面试成功')
					setTimeout(() => {
						uni.$u.route({
							type: 'back'
						})
					}, 1000)
				}
			}
		});
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 0 30rpx;
		padding-bottom: 150rpx;
	}
</style>